package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {
    /**
     * 插入订单数据
     * @param orders
     */
    void insert(Orders orders);

    /**
     * 根据userid 和 订单号查询
     * @param userId
     * @param orderNumber
     * @return
     */
    Orders getByNumberAndId(Long userId, String orderNumber);

    /**
     * 更新订单数据
     * @param orders
     */
    void update(Orders orders);

    /**
     * 处理订单超时的方法
     * @param status
     * @param orderTime
     * @return
     */
    @Select("select * from orders where status=#{status} and order_time =#{orderTime}")
    List<Orders> selectByStatusAndTime(Integer status, LocalDateTime orderTime);

    @Select("select * from orders where id=#{id}")
    Orders selectById(Long id);

    /**
     * 查询
     * @param orders
     * @return
     */
    Page<Orders> select(OrdersPageQueryDTO orders);
    /**
     * 根据状态统计订单数量
     * @param status
     */
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);


    Double selectOrderMoney(LocalDateTime beginTime,LocalDateTime endTime,Integer status);

    Integer selectOrderCountByStatusAndTime(LocalDateTime beginTime, LocalDateTime endTime, Integer status);


    Integer selectBYTimeAndStatus(LocalDateTime time, Integer status);
}
